package com.test.utils;

import com.test.enums.Replay;
import com.test.enums.ReplayCode;

/**
 * ReplayUtil
 *
 * @author HY
 * 2021/05/22 17:09
 **/


public class ReplayUtil {

    /**
     * 返回成功，传入返回体具体出參
     * @param rc
     * @return
     */
    public static Replay success(ReplayCode rc){

        return success(rc, null);
    }
    /**
     * 返回成功，传入返回体具体出參
     * @param rc
     * @param object
     * @return
     */
    public static Replay success(ReplayCode rc, Object object){
        Replay replay = new Replay();
        replay.setCode(rc.getCode());
        replay.setMsg(rc.getMsg());
        replay.setData(object);
        return replay;
    }

    /**
     * 返回成功，传入返回体具体出參
     * @param object
     * @return
     */
    public static Replay success(String msg, Object object){
        Replay replay = new Replay();
        replay.setCode(0);
        replay.setMsg(msg);
        replay.setData(object);
        return replay;
    }

    /**
     * 返回成功，传入返回体具体出參
     * @param object
     * @return
     */
    public static Replay success(String msg, Object object, int count){
        Replay replay = new Replay();
        replay.setCode(0);
        replay.setMsg(msg);
        replay.setData(object);
        replay.setCount(count);
        return replay;
    }

    /**
     * 返回成功，传入返回体具体出參
     * @param object
     * @return
     */
    public static Replay success(Object object){
        return success(ReplayCode.SUCCESS, object);
    }

    /**
     * 返回成功，传入返回体具体出參
     * @param msg
     * @return
     */
    public static Replay success(String msg){
        Replay replay = new Replay();
        replay.setCode(0);
        replay.setMsg(msg);
        return replay;
    }

    /**
     * 提供给部分不需要出參的接口
     * @return
     */
    public static Replay success(){
        return success(ReplayCode.SUCCESS);
    }

    /**
     * 默认错误信息
     * @return
     */
    public static Replay error(){

        return error(ReplayCode.err);
    }

    /**
     * 自定义错误信息
     * @param code
     * @param msg
     * @return
     */
    public static Replay error(Integer code, String msg){
        Replay replay = new Replay();
        replay.setCode(code);
        replay.setMsg(msg);
        replay.setData(null);
        return replay;
    }

    /**
     * 返回异常信息，在已知的范围内
     * @param replayCode
     * @return
     */
    public static Replay error(ReplayCode replayCode){

        return error(replayCode, null);
    }
    /**
     * 返回异常信息，在已知的范围内
     * @param replayCode
     * @return
     */
    public static Replay error(ReplayCode replayCode, Object object){
        Replay replay = new Replay();
        replay.setCode(replayCode.getCode());
        replay.setMsg(replayCode.getMsg());
        replay.setData(object);
        return replay;
    }
}
